package com.example.petshopping.network;

import com.example.petshopping.config.AppConfig;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Retrofit客户端
 */
public class RetrofitClient {

    private static final RetrofitClient INSTANCE = new RetrofitClient();
    private final ApiService apiService;

    private RetrofitClient() {
        // 创建OkHttpClient，添加日志拦截器
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build();

        // 创建Retrofit实例
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(AppConfig.API_BASE_URL)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        // 创建API服务
        apiService = retrofit.create(ApiService.class);
    }

    public static RetrofitClient getInstance() {
        return INSTANCE;
    }

    public ApiService getApiService() {
        return apiService;
    }
} 